package GUI;
/**
 * Select Year so the principle can view the data
 */

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;


import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;


public class PrincipleVpdSelYearnSem extends JPanel {

	private JLabel lblPrincipleViewData = null;
	private JLabel lblSelectYear = null;
	private JComboBox cBSelYear = null;
	private JLabel lblSelectSemester = null;
	private JComboBox cBSeLSemester = null;
	private JButton btnNext = null;
	
	public Login myLoginFrame = null;
	public static Dimension defaultDim=null;
	public UserPrinciple user=null;
	public PrincipleMainMenu prmn = null;
	
	private String selYear = null;
	private String selSem = null;
	
	private PrincipleShowDataScreen showDataScrn = null;
	
	
	
	
	
	public JComboBox getSelYearCb(PrincipleMainMenu prmn)
	{
		int i;
		String[] temp = prmn.user.getSelStudent().split(" ");
				
		Vector<String> years = new Vector <String>();
		
		for(i=0;i<prmn.user.StudentsData.size();i++)
		{
			if(temp[2].equals(prmn.user.StudentsData.get(i).Sid))
			{
			years.addAll(prmn.user.StudentsData.get(i).Years);
			}
		}
		if(cBSelYear==null)
		{
			 cBSelYear = new JComboBox(years);
			 cBSelYear.addActionListener(new ActionListener() {
			 	public void actionPerformed(ActionEvent arg0) {
			 		selYear=cBSelYear.getSelectedItem().toString();
			 		System.out.println(selYear);
			 	}
			 });
			 cBSelYear.setBounds(224, 84, 168, 20);
				
		}
		return cBSelYear;
	}
	
	
	public JComboBox getSelSemesterCb(PrincipleMainMenu prmn)
	{
		String[] semesters = {"A","B"};
		
		if(cBSeLSemester==null)
		{
			cBSeLSemester = new JComboBox(semesters);
			cBSeLSemester.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					selSem = cBSeLSemester.getSelectedItem().toString();
					System.out.println(selSem);
				}
			});
			 cBSeLSemester.setBounds(224, 159, 168, 20);
				
		}
		return cBSeLSemester;
	}
	
	
	public JButton getNexBtn(final PrincipleMainMenu prmn)
	{
		if(btnNext==null)
		{
			 btnNext = new JButton("Show Data");
			 btnNext.addActionListener(new ActionListener() {
			 	public void actionPerformed(ActionEvent e) {
			 		prmn.user.setSelYear(selYear);
			 		prmn.user.setSelSemester(selSem);
			 		showDataScrn = null;
			 		showDataScrn = prmn.getShowDataScrn();
			 		prmn.setContentPane(showDataScrn);
			 		
			 		 
			 		
			 		
			 		System.out.println("All is good :-)");
			 		
			 		
			 	}
			 });
				btnNext.setBounds(529, 309, 89, 23);
		}
		
		return btnNext;
	}
	
	
	private void initialize(PrincipleMainMenu prmn)
	{
		 setLayout(null);
			
		 lblPrincipleViewData = new JLabel("Principle view data");
		 lblPrincipleViewData.setBounds(397, 0, 89, 14);
		add(lblPrincipleViewData);
		
		 lblSelectYear = new JLabel("Select year:");
		 lblSelectYear.setBounds(107, 87, 58, 14);
		add(lblSelectYear);
		
		 lblSelectSemester = new JLabel("Select semester:");
		 lblSelectSemester.setBounds(107, 162, 80, 14);
		add(lblSelectSemester);
		
		add(getSelYearCb(prmn));
		add(getSelSemesterCb(prmn));
		add(getNexBtn(prmn));
		
	}
	

	
	public PrincipleVpdSelYearnSem(PrincipleMainMenu prmn) {
		super();
		initialize(prmn);
	
	}
}
